//
//  HWFirstPageViewController.m
//  HWanGame
//
//  Created by Chendaobin on 2019/8/23.
//  Copyright © 2019年 Chendaobin. All rights reserved.
//

#import "HWFirstPageViewController.h"
#import "HWOnlineGameQCViewController.h"
#import "HWBTViewController.h"
#import "SDCycleScrollViewCdb.h"
#import "HWDiscountViewController.h"
#import "HWH5YouViewController.h"
#import "HWSearchController.h"
#import "HWMessageCenterViewController.h" // 进入消息中心

#import "HWVersionBouncedView.h"

#import "HWfaxiangFoundViewController.h" // 发现
#import "HWRecommendedViewController.h" // 推荐
#import "HWNewBTViewController.h" // 新 BT
       
#import "HWNewdiscountViewController.h"  // 折扣
#import "HWNewH5ViewController.h"  // h5
#import "HWXiaoXiMessageCenterViewController.h"
#import "HWLoginController.h" // 登录界面
#import "HWPersonalDataViewController.h" // 个人资料
#import "HWGroupChatQunViewController.h" // 群聊

#import "HWGameYouXiView.h"


@interface HWFirstPageViewController ()<UITableViewDelegate, UITableViewDataSource, SDCycleScrollViewCdbDelegate, NSURLSessionDelegate,UIScrollViewDelegate,UITextFieldDelegate>
{
    UIImageView *navBarHairlineImageView;
}

@property (nonatomic, strong) NSMutableArray *titleButtons;
@property (nonatomic,strong)  NSMutableArray *biaotiArray;
@property (nonatomic, weak) UIButton *selectButton;
@property (nonatomic, weak) UIScrollView *titleScrollView;
@property (nonatomic, weak) UIScrollView *contentScrollView;
@property (nonatomic, assign) BOOL isInitialize;
@property (strong,nonatomic) UIImageView  *xiantiaoimageview;
@property(weak,nonatomic) UITextField *searchTextField;

@property(strong,nonatomic) UIButton *shuxxingBut;
@property(strong,nonatomic) UIImageView *zhuangtaiLanImageView;

@property(strong,nonatomic) NSMutableArray *kongzhiqiMuArr;
@property(strong,nonatomic) HWVersionBouncedView *versionBounCeView;
@property(strong,nonatomic) NSDictionary *dataDic;
@property(strong,nonatomic) HWGameYouXiView *gameYouXiView;




@end

@implementation HWFirstPageViewController

- (NSMutableArray *)titleButtons
{
    if (_titleButtons == nil) {
        _titleButtons = [NSMutableArray array];
    }
    return _titleButtons;
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
     navBarHairlineImageView.hidden = YES;
    
  //  [self.navigationController.navigationBar setTranslucent:true];
    
    
//    UIImage *backGroundImage = [UIImage imageNamed:@"header-64GaoDu"];
//    backGroundImage = [backGroundImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];
//    [self.navigationController.navigationBar setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];
//
    
    
   // self.navigationController.navigationBar.barTintColor = RGB(217, 247, 250);
//    self.zhuangtaiLanImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, CF_NavHeight)];
//    self.zhuangtaiLanImageView.image = [UIImage imageNamed:@"header_daohang"];
//    [self.navigationController.navigationBar addSubview:self.zhuangtaiLanImageView];
//
    
   // self.navigationController.navigationBar.tintColor = RGB(217, 247, 250);
    
    
    //
    // [UIColor redColor]
    
    
    
    
    
    
}






//- (void)viewWillAppear:(BOOL)animated
//{
//    [super viewWillAppear:animated];
//
//    if (_isInitialize == NO) {
//
//        // 4.设置所有标题
//      //  [self setupAllTitle];
//        _isInitialize = YES;
//    }
//
//}





//获取控制器视图

-(void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    navBarHairlineImageView.hidden = NO;
    self.zhuangtaiLanImageView.hidden = YES;
//    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
//
//    self.navigationController.navigationBar.barTintColor =  [UIColor whiteColor];
//
//
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    NSLog(@"%@",  [NSBundle  currentLanguage]);
    
    // 0 1
  
    navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
    // 设置常用的属性
    [self setproperties];
    // 1.添加标题滚动视图
    [self setupTitleScrollView];
    // 2.添加内容滚动视图
    [self setupContentScrollView];
    
    [self addshuxingkongjian];
    
    //3. 设置标题内容
   // self.biaotiArray = @[@"网游",@"BT版",@"折扣",@"H5游"];
  //  self.biaotiArray = @[@"网游",@"BT版"];
    //发送网络请求
    [self networkRequestData];

//    //4.设置子控制器
//    [self setupAllChildViewController];
//
//    // 5.设置所有标题
//    [self setupAllTitle];

    self.automaticallyAdjustsScrollViewInsets = NO;
    
    // 我的优惠券

    
    // 弹框界面
    [self setuphomepageTanKuangView];
    
    
     [self banbenqueryUpdateversion];
    
 
    
    
    
    
}



#pragma mark ------------ 弹框界面

- (void)setuphomepageTanKuangView {
    
    
    
    NSDictionary *parametes = @{
                                  @"ct" :  @"app",
                                   @"ios" : @"1",
                                   @"ac" : @"pop",
                                  @"member_id":[HWLocallyStoredData getCode],
                             
                                  
                                  };
      [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
          
              [SVProgressHUD dismiss];
          
          
    
              NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
              if ([codeStr intValue] == 1) {
                  
                  NSString *status =  [NSString stringWithFormat:@"%@",response[@"data"][@"status"]];
                  
                  
                  if ([status intValue] == 1) {
                      
                      self.gameYouXiView = [[HWGameYouXiView alloc]init];
                      self.gameYouXiView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
                      self.gameYouXiView.dataDic = response[@"data"];
                      [kKeyWindow addSubview:self.gameYouXiView];
                      
                      
                  }
            
                

              }
              
              NSLog(@"%@",response);
          
          
          
         } failure:^(NSString *error) {
          [SVProgressHUD dismiss];
          
          
        }];
    
    
 
    
    
}














// 查询 app 是否要更新
- (void)banbenqueryUpdateversion
{
    
    
    
   //  UIView *vie =  [[UIView alloc]init];
    
    
     NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
     NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"];
     NSDictionary *parametes = @{
                                  @"ct" :  @"app",
                                   @"ios" : @"1",
                                   @"ac" : @"isupdate",
                                   @"versionCode":appCurVersionNum,
                                   @"member_id":[HWLocallyStoredData getCode],
                                  };
    

    
      [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
          
              [SVProgressHUD dismiss];
          
          
    
              NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
              if ([codeStr intValue] == 1) {
                  
                    
    
                  self.dataDic = response[@"data"];
                  [self shiforios_versionCode:response[@"data"][@"ios_versionCode"]];
                  
                      
                

              }
              
              NSLog(@"%@",response);
          
          
          
         } failure:^(NSString *error) {
          [SVProgressHUD dismiss];
          
          
        }];
    
}





- (void)shiforios_versionCode:(NSString *)dangqiang {
    
    // CFBundleShortVersionString
    
     NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];

     NSString *appCurVersionNum = (NSString *)[infoDictionary objectForKey:@"CFBundleVersion"];
    
    

     NSLog(@"当前应用版本号码：%@",appCurVersionNum);
    
    
    if ([appCurVersionNum  intValue] == [dangqiang intValue] ) {
        
        
        
        
        
        
    } else {
        
        
        
        
        self.versionBounCeView = [[HWVersionBouncedView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
        
        self.versionBounCeView.dataDic  = self.dataDic;
        [self.versionBounCeView refreshData];
        
        [kKeyWindow addSubview:self.versionBounCeView];
        
        
        
          
      
        
    }
    
    
    
    
    
    
    
    
}



- (void)addshuxingkongjian {
    
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"刷新" forState:UIControlStateNormal];
    button.frame = CGRectMake((kScreenW-120)/2, kScreenH/2-24, 120, 40);
    [button setTitleColor:RGB(255, 255 , 255) forState:UIControlStateNormal];
    self.shuxxingBut = button;
    self.shuxxingBut.backgroundColor = RGB(217, 247, 250);
    button.layer.cornerRadius = 20;
    button.layer.masksToBounds = YES;
    
    [button  addTarget:self action:@selector(shuxingTap) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
}

- (void)shuxingTap {
    
    
      [self encrypttheRequestedURL];
    
    
     [self networkRequestData];
    
    
}





- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    
    return nil;

}



// 加载Url
- (void)encrypttheRequestedURL {
    
    
    

    
//    [SDKXIngRequest  encryptionQingqiuUrlStr:EncryptionQingqiuxingYaoSDK success:^(id  _Nullable response) {
//          
//          NSLog(@"%@",response);
//        
//        
//            [self  networkRequestData];
//        
//        
//        
//          
//      } failure:^(NSString * _Nonnull error) {
//          
//          
//           NSLog(@"%@",error);
//          
//      }];
//      
    
    
}




- (void)networkRequestData {
    
    [SVProgressHUD show];
    __weak typeof(self) weakSelf = self;
    self.biaotiArray = [[NSMutableArray alloc]init];
    self.kongzhiqiMuArr = [[NSMutableArray alloc]init];
    NSDictionary *parametes = @{
                                @"ct" :  @"app",
                                @"ios" : @"1",
                                @"ac" : @"config",
                                @"member_id":[HWLocallyStoredData getCode],
                                @"language":@"1",
                                
                                
                                };
    [HWWebUtils do3GetWithParameters:parametes progress:nil success:^(id response) {
        
            [SVProgressHUD dismiss];
        

            NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
            if ([codeStr intValue] == 1) {
                    
                    self.shuxxingBut.hidden = YES;
                    
                    NSString *configStr = [NSString stringWithFormat:@"%@",response[@"data"][@"config"]];
                
                     
                
                   NSArray *arr = response[@"data"][@"index_top"];
                    for (int i = 0; i < arr.count; i++) {
                                                       
                            if ([arr[i][@"status"]  intValue]  == 1){
                                                                    
                                [self.biaotiArray addObject:arr[i][@"name"]];
                                [self.kongzhiqiMuArr addObject:arr[i]];
                            
                            }
                                                       
                                                       
                      }
                                               
                                         //4.设置子控制器
                       [self setupAllChildViewController];
                        // 5.设置所有标题
                       [self setupAllTitle];
                
                
                      return;
                    
                    if ([configStr isEqualToString:@"65415"]) {
                        
                        NSArray *arr = response[@"data"][@"index_top"];
                        for (int i = 0; i < arr.count; i++) {
                                      
                            if ([arr[i][@"status"]  intValue]  == 1){
                                                   
                               [self.biaotiArray addObject:arr[i][@"name"]];
                                [self.kongzhiqiMuArr addObject:arr[i]];
                            }
                                      
                                      
                        }
                              
                        //4.设置子控制器
                        [self setupAllChildViewController];
                        // 5.设置所有标题
                        [self setupAllTitle];

                        
                        
                        
                    } else if ([configStr isEqualToString:@"31561"]) {
                        
                        
                        NSArray *arr = response[@"data"][@"index_top"];
                        for (int i = 0; i < arr.count; i++) {
                                                     
                            if ([arr[i][@"status"]  intValue]  == 1){
                                                   
                                [self.biaotiArray addObject:arr[i][@"name"]];
                                 [self.kongzhiqiMuArr addObject:arr[i]];
                                
                            }
                                                     
                         }
                                             
                          //4.设置子控制器
                           [self setupAllChildViewController];
                           // 5.设置所有标题
                           [self setupAllTitle];
                        
                        
                    } else if ([configStr isEqualToString:@"98751"]) {
                                   
                                   
                        NSArray *arr = response[@"data"][@"index_top"];
                        for (int i = 0; i < arr.count; i++) {
                                                            
                           if ([arr[i][@"status"]  intValue]  == 1) {
                                
                               [self.biaotiArray addObject:arr[i][@"name"]];
                                [self.kongzhiqiMuArr addObject:arr[i]];
                            }
                            
                        }
                        
                        //4.设置子控制器
                        [self setupAllChildViewController];
                            // 5.设置所有标题
                        [self setupAllTitle];
                                   
                                   
                 }
                    
                    
        //            NSArray *arr = response[@"data"][@"index_top"];
        //            for (int i = 0; i < arr.count; i++) {
        //
        //                [self.biaotiArray addObject:arr[i][@"name"]];
        //
        //
        //            }
        //
        //            //4.设置子控制器
        //             [self setupAllChildViewController];
        //            // 5.设置所有标题
        //            [self setupAllTitle];

                }
            
       NSLog(@"%@",response);
        
        
        
    } failure:^(NSString *error) {
        [SVProgressHUD dismiss];
        
        
    }];
    
    
    
    
    

    
}












- (void)setproperties {
    
    self.view.backgroundColor = [UIColor whiteColor];
    // self.navigationController.navigationBar.hidden = YES;
 
//     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageOriginalWithName:@"home_messagexzhongxing"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarBuTap)];
//    
    
//
//    self.zhuangtaiLanImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, CF_NavHeight)];
//    self.zhuangtaiLanImageView.image = [UIImage imageNamed:@"header_daohang"];
//    [self.navigationController.navigationBar addSubview:self.zhuangtaiLanImageView];
//

    UITextField *texfeild = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, kScreenW-90, 30)];
    texfeild.delegate = self;
    texfeild.placeholder = @"请输入关键字搜索";
    texfeild.placeholder = [HWjianzhiduiObject keylocalization:@"请输入关键字搜索"];
    texfeild.font = [UIFont systemFontOfSize:14];
    texfeild.backgroundColor = RGB(244, 243, 252);
    
    
    
   // texfeild.layer.borderColor  = RGB(208, 208, 208).CGColor;
 //   texfeild.layer.borderWidth = 0.5;
//    UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame = CGRectMake(0, 0, 30, 30);
//    [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateNormal];
//      [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateHighlighted];
    
    UIView *sousuoView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 35, 32)];
        UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(5, 0, 30, 30);
        [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateHighlighted];
       [sousuoView addSubview:button];
    
    
    
    texfeild.leftView = sousuoView;
    texfeild.leftViewMode = UITextFieldViewModeAlways;
    texfeild.layer.cornerRadius = 15;
    texfeild.layer.masksToBounds = YES;
   //  texfeild.backgroundColor = [UIColor whiteColor];
    self.navigationItem.titleView = texfeild;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(popUpSearchView)];
    
    [texfeild addGestureRecognizer:tap];
    
    
    
    UIView *yiziView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 28, 28)];
 //    yiziView.layer.cornerRadius = 14;
  //   yiziView.layer.masksToBounds = YES;
    yiziView.backgroundColor = [UIColor clearColor];
    
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(0, 0, 28, 28);
    [button1 setBackgroundImage:[UIImage imageNamed:@"morenTuPenson_ico"] forState:UIControlStateNormal];
    button1.backgroundColor = [UIColor clearColor];
    [button1 addTarget:self action:@selector(buttonTouxiangTap) forControlEvents:UIControlEventTouchUpInside];
    button1.layer.cornerRadius = 6;
    button1.layer.masksToBounds = YES;
    
    [yiziView addSubview:button1];
    
    
    
    
    NSDictionary *dic =  [[NSBundle mainBundle] infoDictionary];
     NSString *icostr =     dic[@"CFBundleIcons"][@"CFBundlePrimaryIcon"][@"CFBundleIconName"];
    //UIImage *appIcon = [UIImage imageNamed: [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIcons"] objectAtIndex:0]];
     UIImage  *appIcon = [UIImage imageNamed:icostr];
     appIcon = [UIImage imageNamed:@"AppIcon"];
     [button1 setBackgroundImage:appIcon forState:UIControlStateNormal];
    
    
    
    
    

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:yiziView];
    
    
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.frame = CGRectMake(0, 0, 30, 30);
 //    [button2 setBackgroundImage:[UIImage imageNamed:@"xiaoxizhongxing"] forState:UIControlStateNormal];
    
     [button2  setImage:[UIImage imageNamed:@"xiaoxizhongxing"] forState:UIControlStateNormal];
    button2.backgroundColor = [UIColor clearColor];
    [button2 addTarget:self action:@selector(button) forControlEvents:UIControlEventTouchUpInside];
//    button2.layer.cornerRadius = 6;
//    button2.layer.masksToBounds = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button2];
    
    
 
    
    
     
    
    
    
    

}


- (void)button {
    
    
    HWXiaoXiMessageCenterViewController *message = [[HWXiaoXiMessageCenterViewController alloc]init];
    [self.navigationController pushViewController:message animated:YES];
    
    
    
    
    
}








#pragma mark ---------    进入我的界面
- (void)buttonTouxiangTap {
    
    
    
     if ([[HWLocallyStoredData getLoginUserID] isEqualToString:@""]) {
               HWLoginController  *login = [[HWLoginController alloc]init];
                 [self.navigationController pushViewController:login animated:YES];
                return;
         
     }
    
    
     
    HWPersonalDataViewController *ziliao = [[HWPersonalDataViewController alloc]init];
    [self.navigationController pushViewController:ziliao animated:YES];
    
     
    
    
    
    
    
    
    
   //   [self.tabBarController setSelectedIndex:4];
    
    
    
    
    
    
    
    
}





#pragma  mark ----------- 点击右边按钮
- (void)leftBarBuTap {
    
    HWMessageCenterViewController *messageCenter = [[HWMessageCenterViewController alloc]init];
    [self.navigationController pushViewController:messageCenter animated:YES];
   
    
}



#pragma mark ---------- UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
   
   // [self popUpSearchView];
    
    
    return NO;
}

- (void)popUpSearchView {
    
    //  1988
    

     HWSearchController *modal = [[HWSearchController alloc]init];
     modal.modalPresentationStyle = UIModalPresentationOverFullScreen;
     [self presentViewController:modal animated:YES completion:nil];
    
    //把当前控制器作为背景
  //  self.definesPresentationContext = YES;
    
    //设置模态视图弹出样式
//    modal.modalPresentationStyle = UIModalPresentationOverFullScreen;
//
////    CATransition * transition = [CATransition animation];
////
////    //设置动画类型（这个是字符串，可以搜索一些更好看的类型）
////    transition.type = @"moveOut";
////
////    //动画出现类型
////    transition.subtype = @"fromCenter";
////
////    //动画时间
////    transition.duration = 0.3;
////
////    //移除当前window的layer层的动画
////    [self.view.window.layer removeAllAnimations];
////    //将定制好的动画添加到当前控制器window的layer层
////    [self.view.window.layer addAnimation:transition forKey:nil];
////
//    [self presentViewController:modal animated:YES completion:nil];
    
    
}




#pragma mark - 设置所有标题
- (void)setupAllTitle
{
    // 已经把内容展示上去 -> 展示的效果是否是我们想要的(调整细节)
    // 1.标题颜色 为黑色
    // 2.需要让titleScrollView可以滚动
    
    // 添加所有标题按钮
    NSInteger count = self.biaotiArray.count;
    CGFloat btnW = 60;
    CGFloat btnH = self.titleScrollView.bounds.size.height;
    CGFloat btnX = 0;
    for (NSInteger i = 0; i < count; i++) {
        
        UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        titleButton.tag = i;
        //  UIViewController *vc = self.childViewControllers[i];
      //   titleButton.backgroundColor = [UIColor redColor];
        [titleButton setTitle:self.biaotiArray[i] forState:UIControlStateNormal];
        CGFloat  jiaju =  (kScreenW - count *60) / (count+ 1);
       
        jiaju =  5;
        
        
        
        btnX = i * btnW + jiaju*(i+1);
        
        titleButton.frame = CGRectMake(btnX, 0, btnW, btnH);
        [titleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //    titleButton.backgroundColor = [UIColor redColor];
        titleButton.titleLabel.font = [UIFont systemFontOfSize:16];
        // 监听按钮点击
        [titleButton addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
        // 把标题按钮保存到对应的数组
        [self.titleButtons addObject:titleButton];
        
        
         
        
    
        
//        if (i == 0) {
//            [self titleClick:titleButton];
//
//            UIImageView *xiantiaoimageview = [[UIImageView alloc]initWithFrame:CGRectMake(btnX+10, btnH-2-6-8, 40, 5)];
//
//            xiantiaoimageview.image = [UIImage imageNamed:@""];
//            xiantiaoimageview.backgroundColor = QCchunseshensetupian;
//            xiantiaoimageview.layer.cornerRadius = 2;
//            xiantiaoimageview.layer.masksToBounds = YES;
//            self.xiantiaoimageview = xiantiaoimageview;
//
//            [self.titleScrollView addSubview:xiantiaoimageview];
//
//        }
//
             if (i == 0) {
                 [self titleClick:titleButton];
                 
                 UIImageView *xiantiaoimageview = [[UIImageView alloc]initWithFrame:CGRectMake(btnX+10, btnH-2-6-8, 40, 5)];
                 
                 xiantiaoimageview.image = [UIImage imageNamed:@""];
                 xiantiaoimageview.backgroundColor = QCchunseshensetupian;
                 xiantiaoimageview.layer.cornerRadius = 2;
                 xiantiaoimageview.layer.masksToBounds = YES;
                 self.xiantiaoimageview = xiantiaoimageview;
                 xiantiaoimageview.hidden = YES;
                 // 这个隐藏 

                 [self.titleScrollView addSubview:xiantiaoimageview];
                 
             }
        
        
        
        [self.titleScrollView addSubview:titleButton];
    }
    
    
    // 设置标题的滚动范围
    self.titleScrollView.contentSize = CGSizeMake(kScreenW, 0);
    self.titleScrollView.showsHorizontalScrollIndicator = NO;
    
    // 设置内容的滚动范围
    self.contentScrollView.contentSize = CGSizeMake(count * kScreenW, 0);
    
    // bug:代码跟我的一模一样,但是标题就是显示不出来
    // 内容往下移动,莫名其妙
}


#pragma mark - 处理标题点击
- (void)titleClick:(UIButton *)button
{
    NSInteger i = button.tag;
    
    // 1.标题颜色 变成 红色
    [self selButton:button];
    
 //    CGRectMake(btnX+25, btnH-2-6, 50, 2)
    
   
    // 2.把对应子控制器的view添加上去
    [self setupOneViewController:i];
    
    // 3.内容滚动视图滚动到对应的位置
    CGFloat x = i * [UIScreen mainScreen].bounds.size.width;
    self.contentScrollView.contentOffset = CGPointMake(x, 0);
}

#pragma mark - 选中标题
- (void)selButton:(UIButton *)button
{
//    [_selectButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [button setTitleColor:QCchunseshensetupian forState:UIControlStateNormal];
//
    
   //  _selectButton = button;
    
    
    
    
    [_selectButton setTitleColor:RGB(68, 68, 68) forState:UIControlStateNormal];
       _selectButton.titleLabel.font = [UIFont systemFontOfSize:14];
       
       
       
       [button setTitleColor:RGB(68, 68, 68) forState:UIControlStateNormal];
       
       [button.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16]];
       
       
     _selectButton = button;
    
    
    
    
    NSInteger i = button.tag;
    NSInteger count = self.biaotiArray.count;
    CGFloat  jiaju =  (kScreenW - count *100) / (count+ 1);
    jiaju = 5;
    CGFloat btnW = 60;
    CGFloat btnX = i * btnW + jiaju*(i+1);
    self.xiantiaoimageview.frame = CGRectMake(btnX+10, 44-2-6-8, 40, 5);
    
    
}


#pragma mark - 添加一个子控制器的View
- (void)setupOneViewController:(NSInteger)i
{
    
    UIViewController *vc = self.childViewControllers[i];
    if (vc.view.superview) {
        return;
    }
    CGFloat x = i * [UIScreen mainScreen].bounds.size.width;
    vc.view.frame = CGRectMake(x, 0,   kScreenW, self.contentScrollView.bounds.size.height);
    [self.contentScrollView addSubview:vc.view];
}







#pragma mark - 添加标题滚动视图
- (void)setupTitleScrollView
{
    // 创建titleScrollView
    UIScrollView *titleScrollView = [[UIScrollView alloc] init];
    CGFloat y = CF_NavHeight;
    
    titleScrollView.frame = CGRectMake(0, y, self.view.bounds.size.width, 44);
    // titleScrollView.backgroundColor = [UIColor redColor];
   // titleScrollView.backgroundColor = RGB(217, 247, 250);
    [self.view addSubview:titleScrollView];
    
    UIImageView *imageview1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
    imageview1.image = [UIImage imageNamed:@"header-44GaoDu"];
    imageview1.hidden = YES;
    [titleScrollView addSubview:imageview1];
    
    
    _titleScrollView = titleScrollView;
    

    
}

#pragma mark - 添加内容滚动视图
- (void)setupContentScrollView
{
    // 创建contentScrollView
    UIScrollView *contentScrollView = [[UIScrollView alloc] init];
    CGFloat y = CGRectGetMaxY(self.titleScrollView.frame);
    contentScrollView.frame = CGRectMake(0, y, self.view.bounds.size.width, self.view.bounds.size.height - y);
    [self.view addSubview:contentScrollView];
    _contentScrollView = contentScrollView;
    
    // 设置contentScrollView的属性
    // 分页
    self.contentScrollView.pagingEnabled = YES;
    // 弹簧
    self.contentScrollView.bounces = NO;
    // 指示器
    self.contentScrollView.showsHorizontalScrollIndicator = NO;
    
    contentScrollView.backgroundColor = [UIColor whiteColor];
    
    // 设置代理.目的:监听内容滚动视图 什么时候滚动完成
    self.contentScrollView.delegate = self;
    
    
    
}


// 只要一滚动就需要字体渐变
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // 字体缩放 1.缩放比例 2.缩放哪两个按钮
    NSInteger leftI = scrollView.contentOffset.x / kScreenW;
    
    UIButton *leftBtn = self.titleButtons[leftI];
    
    // 1.标题颜色 变成 红色
    [self selButton:leftBtn];
    
    // 添加控制器
    [self setupOneViewController:leftI];
    
    
    
}


#pragma mark - 添加所有子控制器
- (void)setupAllChildViewController
{
    
    
//    NSInteger count = self.biaotiArray.count;
//    for (int i = 0 ; i < count ; i++) {
//
//        NSString *string =  self.biaotiArray[i];
//
//
//
//        if ([string isEqualToString:@"网游"]) {
//
//            HWOnlineGameQCViewController * onlineGame = [[HWOnlineGameQCViewController alloc]init];
//            [self addChildViewController:onlineGame];
//
//
//        } else if ( [string isEqualToString:@"BT版"] ) {
//
//            HWBTViewController *bTView = [[HWBTViewController alloc]init];
//            [self addChildViewController:bTView];
//
//
//
//
//
//        } else if ( [string isEqualToString:@"折扣"])  {
//
//            HWDiscountViewController *discount = [[HWDiscountViewController alloc]init];
//            [self addChildViewController:discount];
//
//
//        } else  if  ( [string isEqualToString:@"H5游"]) {
//
//
//            HWH5YouViewController  *h5You = [[HWH5YouViewController alloc]init];
//            [self addChildViewController:h5You];
//
//
//
//        }
//
//
//
//
//    }
//
    
    
  
    
    
    
    
    
    NSInteger count = self.biaotiArray.count;
    
    if (count == 1) {
        NSString *string =  self.biaotiArray[0];
        
        if ([string isEqualToString:@"H5游"]) {
            
            HWH5YouViewController  *h5You = [[HWH5YouViewController alloc]init];
            [self addChildViewController:h5You];
           return;
      
        }
        
        
    }
    
    
    
    
//    for (int i = 0 ; i < count ; i++) {
//
//        if (i == 0 ) {
//
//            HWOnlineGameQCViewController * onlineGame = [[HWOnlineGameQCViewController alloc]init];
//            [self addChildViewController:onlineGame];
//
//
//        } else if ( i == 1) {
//
//            HWBTViewController *bTView = [[HWBTViewController alloc]init];
//            [self addChildViewController:bTView];
//
//
//
//        } else if ( i == 2)  {
//
//            HWDiscountViewController *discount = [[HWDiscountViewController alloc]init];
//
//             [self addChildViewController:discount];
//
//
//
//        } else {
//
//
//            HWH5YouViewController  *h5You = [[HWH5YouViewController alloc]init];
//            [self addChildViewController:h5You];
//
//
//
//        }
//
//    }
    
//    #import "HWRecommendedViewController.h" // 推荐
//    #import "HWNewBTViewController.h" // 新 BT
//
//
//    #import "HWNewdiscountViewController.h"  // 折扣
//    #import "HWNewH5ViewController.h"  // h5
//
    
    for (int i = 0 ; i < count ; i++) {
           
             NSString *type  =  [NSString stringWithFormat:@"%@",self.kongzhiqiMuArr[i][@"type"]];
           NSString *nameStr  =  [NSString stringWithFormat:@"%@",self.kongzhiqiMuArr[i][@"name"]];
             NSInteger typ = [type intValue];

              if (typ == 0 ) {
//发现
                  HWfaxiangFoundViewController *faxiang = [[HWfaxiangFoundViewController alloc]init];
                  faxiang.typeStr  =type;
            
                  [self addChildViewController:faxiang];


              } else if ( typ == 1) {
                  
                  HWRecommendedViewController *tuijian = [[HWRecommendedViewController alloc]init];
                  tuijian.typeStr =type;
                  [self addChildViewController:tuijian];
                  

    

              } else if ( typ == 2)  {
                  //bt
                    HWNewBTViewController *tuijian = [[HWNewBTViewController alloc]init];
                    tuijian.typeStr =type;
                    [self addChildViewController:tuijian];

             



              } else  if (typ == 3){

//折扣
                 HWNewdiscountViewController *zhekou = [[HWNewdiscountViewController alloc]init];
                  zhekou.typeStr =type;
                 [self addChildViewController:zhekou];
                  
                  

                          


              } else  if (typ == 4){
                  
//h5
                   HWNewH5ViewController *zhekou = [[HWNewH5ViewController alloc]init];
                    zhekou.typeStr =type;
                   [self addChildViewController:zhekou];

                  
              } else {
                  //群聊
                  HWGroupChatQunViewController *qunliao =  [[HWGroupChatQunViewController alloc]init];
                  qunliao.typeStr = type;
                  [self addChildViewController:qunliao];

                  
              }

          }
       
    
    
    
    
    
    
    
    
    
    
    
//    for (int i = 0 ; i < count ; i++) {
//
//           NSString *type  =  [NSString stringWithFormat:@"%@",self.kongzhiqiMuArr[i][@"type"]];
//           NSInteger typ = [type intValue];
//
//            if (typ == 0 ) {
//
//                HWOnlineGameQCViewController * onlineGame = [[HWOnlineGameQCViewController alloc]init];
//                [self addChildViewController:onlineGame];
//
//
//            } else if ( typ == 1) {
//
//                HWBTViewController *bTView = [[HWBTViewController alloc]init];
//                [self addChildViewController:bTView];
//
//
//
//            } else if ( typ == 2)  {
//
//                HWDiscountViewController *discount = [[HWDiscountViewController alloc]init];
//
//                 [self addChildViewController:discount];
//
//
//
//            } else {
//
//
//                HWH5YouViewController  *h5You = [[HWH5YouViewController alloc]init];
//                [self addChildViewController:h5You];
//
//
//
//            }
//
//        }
//
    
    
    
    
    
    
    
}










//下面这几个是我主要清理的文件夹：
//
//这里放的是连接真机生成的文件，可以全部删掉或者把不常用的版本删掉，再次连接设备会自动生成
//
//~/Library/Developer/Xcode/iOS DeviceSupport
//
//app打包生成的文件，可以删掉不需要的项目打包文件
//~/Library/Developer/Xcode/Archives

//项目的索引文件等，可以全部删除，或者删除不常用的项目，再次打开项目会自动生成

//~/Library/Developer/Xcode/DerivedData











//跳转 app 的网址

//跳转评论、详情
//
//弹出电话
//
///**
//// 客服电话
//[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", self.lbl_Telphone.text]]]];
//跳转QQ
//
//// 跳到QQ
//NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web", self.qq]];
//[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
//跳转到微信
//
//// 跳到微信
//NSString *str =@"weixin://qr/JnXv90fE6hqVrQOU9yA0";
//[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
//跳转到微信公众号
//
//注：跳转到微信公众号，首先需要到微信开发平台，绑定对应的公众号
//if ([WXApi isWXAppInstalled]) {
//     JumpToBizProfileReq *req = [[JumpToBizProfileReq alloc]init];
//     req.username = @"公众号原始ID";
//      req.extMsg = @"";
//     req.profileType =0;
//     [WXApi sendReq:req];
//} else {
//     UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
//     [pasteboard setString:self.weChatID];
//     [QQMMessage showSuccessMessage:@"已复制公众号"];
//}










@end


#pragma mark ----------------  以前的代码






//#import "HWFirstPageViewController.h"
//#import "HWOnlineGameQCViewController.h"
//#import "HWBTViewController.h"
//#import "SDCycleScrollViewCdb.h"
//#import "HWDiscountViewController.h"
//#import "HWH5YouViewController.h"
//#import "HWSearchController.h"
//#import "HWMessageCenterViewController.h" // 进入消息中心
//
//#import "HWVersionBouncedView.h"
//
//
//
//@interface HWFirstPageViewController ()<UITableViewDelegate, UITableViewDataSource, SDCycleScrollViewCdbDelegate, NSURLSessionDelegate,UIScrollViewDelegate,UITextFieldDelegate>
//{
//    UIImageView *navBarHairlineImageView;
//}
//
//@property (nonatomic, strong) NSMutableArray *titleButtons;
//@property (nonatomic,strong)  NSMutableArray *biaotiArray;
//@property (nonatomic, weak) UIButton *selectButton;
//@property (nonatomic, weak) UIScrollView *titleScrollView;
//@property (nonatomic, weak) UIScrollView *contentScrollView;
//@property (nonatomic, assign) BOOL isInitialize;
//@property (strong,nonatomic) UIImageView  *xiantiaoimageview;
//@property(weak,nonatomic) UITextField *searchTextField;
//
//@property(strong,nonatomic) UIButton *shuxxingBut;
//@property(strong,nonatomic) UIImageView *zhuangtaiLanImageView;
//
//@property(strong,nonatomic) NSMutableArray *kongzhiqiMuArr;
//@property(strong,nonatomic) HWVersionBouncedView *versionBounCeView;
//@property(strong,nonatomic) NSDictionary *dataDic;
//
//
//
//
//
//
//@end
//
//@implementation HWFirstPageViewController
//
//- (NSMutableArray *)titleButtons
//{
//    if (_titleButtons == nil) {
//        _titleButtons = [NSMutableArray array];
//    }
//    return _titleButtons;
//}
//
//- (void)viewWillAppear:(BOOL)animated {
//
//    [super viewWillAppear:animated];
//
//     navBarHairlineImageView.hidden = YES;
//
//  //  [self.navigationController.navigationBar setTranslucent:true];
//
//
//    UIImage *backGroundImage = [UIImage imageNamed:@"header-64GaoDu"];
//    backGroundImage = [backGroundImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];
//    [self.navigationController.navigationBar setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];
//
//
//
//   // self.navigationController.navigationBar.barTintColor = RGB(217, 247, 250);
////    self.zhuangtaiLanImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, CF_NavHeight)];
////    self.zhuangtaiLanImageView.image = [UIImage imageNamed:@"header_daohang"];
////    [self.navigationController.navigationBar addSubview:self.zhuangtaiLanImageView];
////
//
//   // self.navigationController.navigationBar.tintColor = RGB(217, 247, 250);
//
//
//
//
//
//
//
//}
//
//
//
//
//
//
////- (void)viewWillAppear:(BOOL)animated
////{
////    [super viewWillAppear:animated];
////
////    if (_isInitialize == NO) {
////
////        // 4.设置所有标题
////      //  [self setupAllTitle];
////        _isInitialize = YES;
////    }
////
////}
//
//
//
//
//
////获取控制器视图
//
//-(void)viewWillDisappear:(BOOL)animated {
//
//    [super viewWillDisappear:animated];
//    navBarHairlineImageView.hidden = NO;
//    self.zhuangtaiLanImageView.hidden = YES;
//    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
//
//    self.navigationController.navigationBar.barTintColor =  [UIColor whiteColor];
//
//
//}
//
//
//- (void)viewDidLoad {
//    [super viewDidLoad];
//
//    navBarHairlineImageView = [self findHairlineImageViewUnder:  self.navigationController.navigationBar];
//    // 设置常用的属性
//    [self setproperties];
//    // 1.添加标题滚动视图
//    [self setupTitleScrollView];
//    // 2.添加内容滚动视图
//    [self setupContentScrollView];
//
//    [self addshuxingkongjian];
//
//    //3. 设置标题内容
//   // self.biaotiArray = @[@"网游",@"BT版",@"折扣",@"H5游"];
//  //  self.biaotiArray = @[@"网游",@"BT版"];
//    //发送网络请求
//    [self networkRequestData];
//
////    //4.设置子控制器
////    [self setupAllChildViewController];
////
////    // 5.设置所有标题
////    [self setupAllTitle];
//
//   self.automaticallyAdjustsScrollViewInsets = NO;
//
//
//
//    [self banbenqueryUpdateversion];
//
//  //  [self fasomngshiping];
//
//
//
//
//}
//
//
//
//- (void)fasomngshiping {
//
//
// return;
//
//
//        NSString *uid = [HWLocallyStoredData getLoginUserID];
//        NSString *tString = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
//      //  NSString *gidStr = [NSString stringWithFormat:@"%@",self.gameId];
//        NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tString,@"fsd213ewdsadqwe2121213edsad"];
//        NSString *signMD5 = [WMUtil md5HexDigest:signStr];
//
//        NSString *type = @"0";
//
//        NSDictionary *parametes = @{
//
//
//                          @"ct":@"app",
//                          @"ac":@"video",
//
//
//        };
//
//
//
//
//
//
//
//
//
//
//        [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
//
//
//
//            NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//
//            if ([codeStr intValue] == 1) {
//               // [MBProgressHUD showMessage:@"收藏成功" toView:self.view];
//
//
//
//
//
//            } else {
//
//
//               // [MBProgressHUD showError:@"收藏失败"];
//               [MBProgressHUD showError:response[@"message"]];
//
//            }
//
//
//
//        } failure:^(NSString *error) {
//
//
//            [MBProgressHUD showError:@"收藏失败"];
//
//        }];
//
//
//
//
//
//
//}
//
//
//
//
//
//
//
//
//
//
//// 查询 app 是否要更新
//- (void)banbenqueryUpdateversion
//{
//
//
//
//     NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
//     NSString *appCurVersionNum = [infoDictionary objectForKey:@"CFBundleVersion"];
//
//
//    NSDictionary *parametes = @{
//                                  @"ct" :  @"app",
//                                   @"ios" : @"1",
//                                   @"ac" : @"isupdate",
//                                   @"versionCode":appCurVersionNum,
//
//
//                                  };
//      [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
//
//              [SVProgressHUD dismiss];
//
//
//
//              NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//              if ([codeStr intValue] == 1) {
//
//
//
//                  self.dataDic = response[@"data"];
//
//                  [self shiforios_versionCode:response[@"data"][@"ios_versionCode"]];
//
//
//
//
//              }
//
//              NSLog(@"%@",response);
//
//
//
//         } failure:^(NSString *error) {
//          [SVProgressHUD dismiss];
//
//
//        }];
//
//}
//
//
//
//
//
//- (void)shiforios_versionCode:(NSString *)dangqiang {
//
//    // CFBundleShortVersionString
//
//     NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
//
//     NSString *appCurVersionNum = (NSString *)[infoDictionary objectForKey:@"CFBundleVersion"];
//
//
//
//     NSLog(@"当前应用版本号码：%@",appCurVersionNum);
//
//
//    if ([appCurVersionNum  intValue] == [dangqiang intValue] ) {
//
//
//
//
//
//    } else {
//
//
//
//
//        self.versionBounCeView = [[HWVersionBouncedView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
//
//        self.versionBounCeView.dataDic  = self.dataDic;
//        [self.versionBounCeView refreshData];
//
//        [kKeyWindow addSubview:self.versionBounCeView];
//
//
//
//
//
//
//
//    }
//
//
//
//
//
//
//
//
//}
//
//
//
//- (void)addshuxingkongjian {
//
//
//
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    [button setTitle:@"刷新" forState:UIControlStateNormal];
//    button.frame = CGRectMake((kScreenW-120)/2, kScreenH/2-24, 120, 40);
//    [button setTitleColor:RGB(255, 255 , 255) forState:UIControlStateNormal];
//    self.shuxxingBut = button;
//    self.shuxxingBut.backgroundColor = RGB(217, 247, 250);
//    button.layer.cornerRadius = 20;
//    button.layer.masksToBounds = YES;
//
//    [button  addTarget:self action:@selector(shuxingTap) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:button];
//
//}
//
//- (void)shuxingTap {
//
//     [self networkRequestData];
//
//
//}
//
//
//
//
//
//- (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
//    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
//        return (UIImageView *)view;
//    }
//    for (UIView *subview in view.subviews) {
//        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
//        if (imageView) {
//            return imageView;
//        }
//    }
//
//    return nil;
//
//}
//
//
//
//- (void)networkRequestData {
//
//    [SVProgressHUD show];
//    __weak typeof(self) weakSelf = self;
//    self.biaotiArray = [[NSMutableArray alloc]init];
//    self.kongzhiqiMuArr = [[NSMutableArray alloc]init];
//    NSDictionary *parametes = @{
//                                @"ct" :  @"app",
//                                 @"ios" : @"1",
//                                @"ac" : @"config"
//
//                                };
//    [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
//
//            [SVProgressHUD dismiss];
//
//
//
//
//            NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//            if ([codeStr intValue] == 1) {
//
//                    self.shuxxingBut.hidden = YES;
//
//                    NSString *configStr = [NSString stringWithFormat:@"%@",response[@"data"][@"config"]];
//
//                    if ([configStr isEqualToString:@"65415"]) {
//
//                        NSArray *arr = response[@"data"][@"index_top"];
//                        for (int i = 0; i < arr.count; i++) {
//
//                            if ([arr[i][@"status"]  intValue]  == 1){
//
//                               [self.biaotiArray addObject:arr[i][@"name"]];
//                                [self.kongzhiqiMuArr addObject:arr[i]];
//                            }
//
//
//                        }
//
//                        //4.设置子控制器
//                        [self setupAllChildViewController];
//                        // 5.设置所有标题
//                        [self setupAllTitle];
//
//
//
//
//                    } else if ([configStr isEqualToString:@"31561"]) {
//
//
//                        NSArray *arr = response[@"data"][@"index_top"];
//                        for (int i = 0; i < arr.count; i++) {
//
//                            if ([arr[i][@"status"]  intValue]  == 1){
//
//                                [self.biaotiArray addObject:arr[i][@"name"]];
//                                 [self.kongzhiqiMuArr addObject:arr[i]];
//
//                            }
//
//                         }
//
//                          //4.设置子控制器
//                           [self setupAllChildViewController];
//                           // 5.设置所有标题
//                           [self setupAllTitle];
//
//
//                    } else if ([configStr isEqualToString:@"98751"]) {
//
//
//                        NSArray *arr = response[@"data"][@"index_top"];
//                        for (int i = 0; i < arr.count; i++) {
//
//                           if ([arr[i][@"status"]  intValue]  == 1) {
//
//                               [self.biaotiArray addObject:arr[i][@"name"]];
//                                [self.kongzhiqiMuArr addObject:arr[i]];
//                            }
//
//                        }
//
//                        //4.设置子控制器
//                        [self setupAllChildViewController];
//                            // 5.设置所有标题
//                        [self setupAllTitle];
//
//
//                 }
//
//
//        //            NSArray *arr = response[@"data"][@"index_top"];
//        //            for (int i = 0; i < arr.count; i++) {
//        //
//        //                [self.biaotiArray addObject:arr[i][@"name"]];
//        //
//        //
//        //            }
//        //
//        //            //4.设置子控制器
//        //             [self setupAllChildViewController];
//        //            // 5.设置所有标题
//        //            [self setupAllTitle];
//
//                }
//
//       NSLog(@"%@",response);
//
//
//
//    } failure:^(NSString *error) {
//        [SVProgressHUD dismiss];
//
//
//    }];
//
//
//
//
//
//
//
//}
//
//
//
//
//
//
//
//
//
//
//
//
//- (void)setproperties {
//
//    self.view.backgroundColor = [UIColor whiteColor];
//    // self.navigationController.navigationBar.hidden = YES;
//
////     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageOriginalWithName:@"home_messagexzhongxing"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarBuTap)];
////
//
////
////    self.zhuangtaiLanImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, CF_NavHeight)];
////    self.zhuangtaiLanImageView.image = [UIImage imageNamed:@"header_daohang"];
////    [self.navigationController.navigationBar addSubview:self.zhuangtaiLanImageView];
////
//
//    UITextField *texfeild = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, kScreenW-90, 30)];
//    texfeild.delegate = self;
//    texfeild.placeholder = @"快来搜索你喜欢的游戏";
//    texfeild.font = [UIFont systemFontOfSize:14];
//   // texfeild.layer.borderColor  = RGB(208, 208, 208).CGColor;
// //   texfeild.layer.borderWidth = 0.5;
////    UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
////    button.frame = CGRectMake(0, 0, 30, 30);
////    [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateNormal];
////      [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateHighlighted];
//
//    UIView *sousuoView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 35, 32)];
//        UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
//        button.frame = CGRectMake(5, 0, 30, 30);
//        [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateNormal];
//        [button setImage:[UIImage imageNamed:@"sousukuananniu_ico"] forState:UIControlStateHighlighted];
//       [sousuoView addSubview:button];
//
//
//
//    texfeild.leftView = sousuoView;
//    texfeild.leftViewMode = UITextFieldViewModeAlways;
//    texfeild.layer.cornerRadius = 15;
//    texfeild.layer.masksToBounds = YES;
//    texfeild.backgroundColor = [UIColor whiteColor];
//    self.navigationItem.titleView = texfeild;
//
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(popUpSearchView)];
//
//    [texfeild addGestureRecognizer:tap];
//
//
//
//    UIView *yiziView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 28, 28)];
//    yiziView.layer.cornerRadius = 14;
//    yiziView.layer.masksToBounds = YES;
//    yiziView.backgroundColor = [UIColor redColor];
//
//
//    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
//    button1.frame = CGRectMake(0, 0, 28, 28);
//    [button1 setBackgroundImage:[UIImage imageNamed:@"morenTuPenson_ico"] forState:UIControlStateNormal];
//    button1.backgroundColor = [UIColor redColor];
//    [button1 addTarget:self action:@selector(buttonTouxiangTap) forControlEvents:UIControlEventTouchUpInside];
//    button1.layer.cornerRadius = 14;
//    button1.layer.masksToBounds = YES;
//
//    [yiziView addSubview:button1];
//
//
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:yiziView];
//
//
//
//}
//#pragma mark ---------    进入我的界面
//- (void)buttonTouxiangTap {
//
//    [self.tabBarController setSelectedIndex:3];
//
//
//}
//
//
//
//
//
//#pragma  mark ----------- 点击右边按钮
//- (void)leftBarBuTap {
//
//    HWMessageCenterViewController *messageCenter = [[HWMessageCenterViewController alloc]init];
//    [self.navigationController pushViewController:messageCenter animated:YES];
//
//
//}
//
//
//
//#pragma mark ---------- UITextFieldDelegate
//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
//
//   // [self popUpSearchView];
//
//
//    return NO;
//}
//
//- (void)popUpSearchView {
//
//
//     HWSearchController *modal = [[HWSearchController alloc]init];
//     modal.modalPresentationStyle = UIModalPresentationOverFullScreen;
//     [self presentViewController:modal animated:YES completion:nil];
//
//    //把当前控制器作为背景
//  //  self.definesPresentationContext = YES;
//
//    //设置模态视图弹出样式
////    modal.modalPresentationStyle = UIModalPresentationOverFullScreen;
////
//////    CATransition * transition = [CATransition animation];
//////
//////    //设置动画类型（这个是字符串，可以搜索一些更好看的类型）
//////    transition.type = @"moveOut";
//////
//////    //动画出现类型
//////    transition.subtype = @"fromCenter";
//////
//////    //动画时间
//////    transition.duration = 0.3;
//////
//////    //移除当前window的layer层的动画
//////    [self.view.window.layer removeAllAnimations];
//////    //将定制好的动画添加到当前控制器window的layer层
//////    [self.view.window.layer addAnimation:transition forKey:nil];
//////
////    [self presentViewController:modal animated:YES completion:nil];
//
//
//}
//
//
//
//
//#pragma mark - 设置所有标题
//- (void)setupAllTitle
//{
//    // 已经把内容展示上去 -> 展示的效果是否是我们想要的(调整细节)
//    // 1.标题颜色 为黑色
//    // 2.需要让titleScrollView可以滚动
//
//    // 添加所有标题按钮
//    NSInteger count = self.biaotiArray.count;
//    CGFloat btnW = 100;
//    CGFloat btnH = self.titleScrollView.bounds.size.height;
//    CGFloat btnX = 0;
//    for (NSInteger i = 0; i < count; i++) {
//
//        UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        titleButton.tag = i;
//        //  UIViewController *vc = self.childViewControllers[i];
//        [titleButton setTitle:self.biaotiArray[i] forState:UIControlStateNormal];
//        CGFloat  jiaju =  (kScreenW - count *100) / (count+ 1);
//
//        btnX = i * btnW + jiaju*(i+1);
//
//        titleButton.frame = CGRectMake(btnX, 0, btnW, btnH);
//        [titleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        //    titleButton.backgroundColor = [UIColor redColor];
//        titleButton.titleLabel.font = [UIFont systemFontOfSize:16];
//        // 监听按钮点击
//        [titleButton addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
//        // 把标题按钮保存到对应的数组
//        [self.titleButtons addObject:titleButton];
//
//
//
//        if (i == 0) {
//            [self titleClick:titleButton];
//
//            UIImageView *xiantiaoimageview = [[UIImageView alloc]initWithFrame:CGRectMake(btnX+25, btnH-2-6, 50, 2)];
//
//            xiantiaoimageview.image = [UIImage imageNamed:@""];
//            xiantiaoimageview.backgroundColor = RGB(53, 115, 246);
//            xiantiaoimageview.layer.cornerRadius = 1;
//            xiantiaoimageview.layer.masksToBounds = YES;
//            self.xiantiaoimageview = xiantiaoimageview;
//
//            [self.titleScrollView addSubview:xiantiaoimageview];
//
//        }
//
//        [self.titleScrollView addSubview:titleButton];
//    }
//
//
//    // 设置标题的滚动范围
//    self.titleScrollView.contentSize = CGSizeMake(kScreenW, 0);
//    self.titleScrollView.showsHorizontalScrollIndicator = NO;
//
//    // 设置内容的滚动范围
//    self.contentScrollView.contentSize = CGSizeMake(count * kScreenW, 0);
//
//    // bug:代码跟我的一模一样,但是标题就是显示不出来
//    // 内容往下移动,莫名其妙
//}
//
//
//#pragma mark - 处理标题点击
//- (void)titleClick:(UIButton *)button
//{
//    NSInteger i = button.tag;
//
//    // 1.标题颜色 变成 红色
//    [self selButton:button];
//
// //    CGRectMake(btnX+25, btnH-2-6, 50, 2)
//
//
//    // 2.把对应子控制器的view添加上去
//    [self setupOneViewController:i];
//
//    // 3.内容滚动视图滚动到对应的位置
//    CGFloat x = i * [UIScreen mainScreen].bounds.size.width;
//    self.contentScrollView.contentOffset = CGPointMake(x, 0);
//}
//
//#pragma mark - 选中标题
//- (void)selButton:(UIButton *)button
//{
//    [_selectButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [button setTitleColor:RGB(53, 115, 246) forState:UIControlStateNormal];
//    _selectButton = button;
//
//    NSInteger i = button.tag;
//    NSInteger count = self.biaotiArray.count;
//    CGFloat  jiaju =  (kScreenW - count *100) / (count+ 1);
//    CGFloat btnW = 100;
//    CGFloat btnX = i * btnW + jiaju*(i+1);
//    self.xiantiaoimageview.frame = CGRectMake(btnX+25, 44-2-6, 50, 2);
//
//
//}
//
//
//#pragma mark - 添加一个子控制器的View
//- (void)setupOneViewController:(NSInteger)i
//{
//
//    UIViewController *vc = self.childViewControllers[i];
//    if (vc.view.superview) {
//        return;
//    }
//    CGFloat x = i * [UIScreen mainScreen].bounds.size.width;
//    vc.view.frame = CGRectMake(x, 0,   kScreenW, self.contentScrollView.bounds.size.height);
//    [self.contentScrollView addSubview:vc.view];
//}
//
//
//
//
//
//
//
//#pragma mark - 添加标题滚动视图
//- (void)setupTitleScrollView
//{
//    // 创建titleScrollView
//    UIScrollView *titleScrollView = [[UIScrollView alloc] init];
//    CGFloat y = CF_NavHeight;
//
//    titleScrollView.frame = CGRectMake(0, y, self.view.bounds.size.width, 44);
//    // titleScrollView.backgroundColor = [UIColor redColor];
//   // titleScrollView.backgroundColor = RGB(217, 247, 250);
//    [self.view addSubview:titleScrollView];
//
//    UIImageView *imageview1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
//    imageview1.image = [UIImage imageNamed:@"header-44GaoDu"];
//    [titleScrollView addSubview:imageview1];
//
//
//    _titleScrollView = titleScrollView;
//
//
//
//}
//
//#pragma mark - 添加内容滚动视图
//- (void)setupContentScrollView
//{
//    // 创建contentScrollView
//    UIScrollView *contentScrollView = [[UIScrollView alloc] init];
//    CGFloat y = CGRectGetMaxY(self.titleScrollView.frame);
//    contentScrollView.frame = CGRectMake(0, y, self.view.bounds.size.width, self.view.bounds.size.height - y);
//    [self.view addSubview:contentScrollView];
//    _contentScrollView = contentScrollView;
//
//    // 设置contentScrollView的属性
//    // 分页
//    self.contentScrollView.pagingEnabled = YES;
//    // 弹簧
//    self.contentScrollView.bounces = NO;
//    // 指示器
//    self.contentScrollView.showsHorizontalScrollIndicator = NO;
//
//    contentScrollView.backgroundColor = [UIColor whiteColor];
//
//    // 设置代理.目的:监听内容滚动视图 什么时候滚动完成
//    self.contentScrollView.delegate = self;
//
//
//
//}
//
//
//// 只要一滚动就需要字体渐变
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    // 字体缩放 1.缩放比例 2.缩放哪两个按钮
//    NSInteger leftI = scrollView.contentOffset.x / kScreenW;
//
//    UIButton *leftBtn = self.titleButtons[leftI];
//
//    // 1.标题颜色 变成 红色
//    [self selButton:leftBtn];
//
//    // 添加控制器
//    [self setupOneViewController:leftI];
//
//
//
//}
//
//
//#pragma mark - 添加所有子控制器
//- (void)setupAllChildViewController
//{
//
//
////    NSInteger count = self.biaotiArray.count;
////    for (int i = 0 ; i < count ; i++) {
////
////        NSString *string =  self.biaotiArray[i];
////
////
////
////        if ([string isEqualToString:@"网游"]) {
////
////            HWOnlineGameQCViewController * onlineGame = [[HWOnlineGameQCViewController alloc]init];
////            [self addChildViewController:onlineGame];
////
////
////        } else if ( [string isEqualToString:@"BT版"] ) {
////
////            HWBTViewController *bTView = [[HWBTViewController alloc]init];
////            [self addChildViewController:bTView];
////
////
////
////
////
////        } else if ( [string isEqualToString:@"折扣"])  {
////
////            HWDiscountViewController *discount = [[HWDiscountViewController alloc]init];
////            [self addChildViewController:discount];
////
////
////        } else  if  ( [string isEqualToString:@"H5游"]) {
////
////
////            HWH5YouViewController  *h5You = [[HWH5YouViewController alloc]init];
////            [self addChildViewController:h5You];
////
////
////
////        }
////
////
////
////
////    }
////
//
//
//
//
//
//
//
//
//    NSInteger count = self.biaotiArray.count;
//
//    if (count == 1) {
//        NSString *string =  self.biaotiArray[0];
//
//        if ([string isEqualToString:@"H5游"]) {
//
//            HWH5YouViewController  *h5You = [[HWH5YouViewController alloc]init];
//           [self addChildViewController:h5You];
//           return;
//
//        }
//
//
//    }
//
//
//
//
////    for (int i = 0 ; i < count ; i++) {
////
////        if (i == 0 ) {
////
////            HWOnlineGameQCViewController * onlineGame = [[HWOnlineGameQCViewController alloc]init];
////            [self addChildViewController:onlineGame];
////
////
////        } else if ( i == 1) {
////
////            HWBTViewController *bTView = [[HWBTViewController alloc]init];
////            [self addChildViewController:bTView];
////
////
////
////        } else if ( i == 2)  {
////
////            HWDiscountViewController *discount = [[HWDiscountViewController alloc]init];
////
////             [self addChildViewController:discount];
////
////
////
////        } else {
////
////
////            HWH5YouViewController  *h5You = [[HWH5YouViewController alloc]init];
////            [self addChildViewController:h5You];
////
////
////
////        }
////
////    }
//
//
//
//    for (int i = 0 ; i < count ; i++) {
//
//           NSString *type  =  [NSString stringWithFormat:@"%@",self.kongzhiqiMuArr[i][@"type"]];
//           NSInteger typ = [type intValue];
//
//            if (typ == 0 ) {
//
//                HWOnlineGameQCViewController * onlineGame = [[HWOnlineGameQCViewController alloc]init];
//                [self addChildViewController:onlineGame];
//
//
//            } else if ( typ == 1) {
//
//                HWBTViewController *bTView = [[HWBTViewController alloc]init];
//                [self addChildViewController:bTView];
//
//
//
//            } else if ( typ == 2)  {
//
//                HWDiscountViewController *discount = [[HWDiscountViewController alloc]init];
//
//                 [self addChildViewController:discount];
//
//
//
//            } else {
//
//
//                HWH5YouViewController  *h5You = [[HWH5YouViewController alloc]init];
//                [self addChildViewController:h5You];
//
//
//
//            }
//
//        }
//
//
//
//
//
//
//
//
//}
//
//
//
//
//
//
//
//
//
//
////下面这几个是我主要清理的文件夹：
////
////这里放的是连接真机生成的文件，可以全部删掉或者把不常用的版本删掉，再次连接设备会自动生成
////
////~/Library/Developer/Xcode/iOS DeviceSupport
////
////app打包生成的文件，可以删掉不需要的项目打包文件
////~/Library/Developer/Xcode/Archives
//
////项目的索引文件等，可以全部删除，或者删除不常用的项目，再次打开项目会自动生成
//
////~/Library/Developer/Xcode/DerivedData
////
//
//
////跳转 app 的网址
//
////跳转评论、详情
////
////弹出电话
////
/////**
//// *  客服电话
////// 客服电话
////[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", self.lbl_Telphone.text]]]];
////跳转QQ
////
////// 跳到QQ
////NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web", self.qq]];
////[self.webView loadRequest:[NSURLRequest requestWithURL:url]];
////跳转到微信
////
////// 跳到微信
////NSString *str =@"weixin://qr/JnXv90fE6hqVrQOU9yA0";
////[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
////跳转到微信公众号
////
////注：跳转到微信公众号，首先需要到微信开发平台，绑定对应的公众号
////if ([WXApi isWXAppInstalled]) {
////     JumpToBizProfileReq *req = [[JumpToBizProfileReq alloc]init];
////     req.username = @"公众号原始ID";
////      req.extMsg = @"";
////     req.profileType =0;
////     [WXApi sendReq:req];
////} else {
////     UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
////     [pasteboard setString:self.weChatID];
////     [QQMMessage showSuccessMessage:@"已复制公众号"];
////}
//
//
//
//
//
//
//
//
//
//
//@end
//

